// 2025/11/5
// 无重复字符的最长子串

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int l = 0, r = 0, n = s.size(), ans = 0;
        unordered_set<char> mp;
        for(r = 0; r < n; r++)
        {
            if(mp.count(s[r]) == 0)
            {
                mp.emplace(s[r]);
                ans = max(ans, (int)mp.size());
            }
            else
            {
                while(s[l] != s[r])
                {
                    mp.erase(s[l++]);
                }
                l++;
            }
        }
        return ans;
    }
};